package com.myself.module.source.sort;

import java.util.Arrays;

/**
 * @author 瑟瑟发抖
 * @version 1.0
 * @description 插入排序
 * @date 2024/4/12 15:36
 */
public class InsertSort {
    public static int[] sort(int[] input) {

        for (int i = 0; i < input.length; i++) {
            for (int j = input.length - 1; j > 0 && input[j] < input[i]; j--) {
                int middleInt = input[i];
                input[i] = input[j];
                input[j] = middleInt;
            }
        }


        return input;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(sort(new int[]{1, 8, 9, 5, 4})));
    }
}
